/**
 * Validiert die Anzahl der Tickets.
 * 
 * @author Michael Serajnik
 */

package at.fhj.itm10.ticketmaster.validators;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

@FacesValidator(value = "TicketAmountValidator")
public class TicketAmountValidator implements Validator {

	public void validate(FacesContext context, UIComponent component, Object value)
			throws ValidatorException {
		
		String ticketAmount = String.valueOf(value);
		String regEx = "^[1-9]+[0-9]*$";
		
		if(ticketAmount.length() == 0 || ticketAmount.matches(regEx) == false) {
			throw new ValidatorException(new FacesMessage("Bitte gib eine g\u00FCltige Anzahl an Tickets an."));
		}
		
	}

}